<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.7"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>qLibc: utilities/qfile.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">qLibc
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('qfile_8c.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">qfile.c File Reference</div></div>
</div><!--header-->
<div class="contents">

<p>File handling APIs.  
<a href="#details">More...</a></p>

<p><a href="qfile_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="define-members" name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a5e813a1311d212940f55ab4686933d1f"><td class="memItemLeft" align="right" valign="top"><a id="a5e813a1311d212940f55ab4686933d1f" name="a5e813a1311d212940f55ab4686933d1f"></a>
#define&#160;</td><td class="memItemRight" valign="bottom"><b>MAX_EXTENSION_LENGTH</b>&#160;&#160;&#160;(8)</td></tr>
<tr class="separator:a5e813a1311d212940f55ab4686933d1f"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:aee13ab9a468771f9b4e60ae117d1f613"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#aee13ab9a468771f9b4e60ae117d1f613">qfile_lock</a> (int fd)</td></tr>
<tr class="memdesc:aee13ab9a468771f9b4e60ae117d1f613"><td class="mdescLeft">&#160;</td><td class="mdescRight">Lock file.  <br /></td></tr>
<tr class="separator:aee13ab9a468771f9b4e60ae117d1f613"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a964a6571f9178ce478d61fe7c4f1021e"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#a964a6571f9178ce478d61fe7c4f1021e">qfile_unlock</a> (int fd)</td></tr>
<tr class="memdesc:a964a6571f9178ce478d61fe7c4f1021e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Unlock file which is locked by <a class="el" href="qfile_8c.html#aee13ab9a468771f9b4e60ae117d1f613" title="Lock file.">qfile_lock()</a>  <br /></td></tr>
<tr class="separator:a964a6571f9178ce478d61fe7c4f1021e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af22eeea721ad66346d7e19f82b28fdb0"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#af22eeea721ad66346d7e19f82b28fdb0">qfile_exist</a> (const char *filepath)</td></tr>
<tr class="memdesc:af22eeea721ad66346d7e19f82b28fdb0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check file existence.  <br /></td></tr>
<tr class="separator:af22eeea721ad66346d7e19f82b28fdb0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2e381f2cbdcbeeaee40dc754414cbe01"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#a2e381f2cbdcbeeaee40dc754414cbe01">qfile_load</a> (const char *filepath, size_t *nbytes)</td></tr>
<tr class="memdesc:a2e381f2cbdcbeeaee40dc754414cbe01"><td class="mdescLeft">&#160;</td><td class="mdescRight">Load file into memory.  <br /></td></tr>
<tr class="separator:a2e381f2cbdcbeeaee40dc754414cbe01"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9133efad385ea27ea68c6df8fb94f1c4"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#a9133efad385ea27ea68c6df8fb94f1c4">qfile_read</a> (FILE *fp, size_t *nbytes)</td></tr>
<tr class="memdesc:a9133efad385ea27ea68c6df8fb94f1c4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Read data from a file stream.  <br /></td></tr>
<tr class="separator:a9133efad385ea27ea68c6df8fb94f1c4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaef22ff4a8a80e6356583335cc34db64"><td class="memItemLeft" align="right" valign="top">ssize_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#aaef22ff4a8a80e6356583335cc34db64">qfile_save</a> (const char *filepath, const void *buf, size_t size, bool append)</td></tr>
<tr class="memdesc:aaef22ff4a8a80e6356583335cc34db64"><td class="mdescLeft">&#160;</td><td class="mdescRight">Save data into file.  <br /></td></tr>
<tr class="separator:aaef22ff4a8a80e6356583335cc34db64"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae623f84683c9aa6f58ead2f16a8f63db"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#ae623f84683c9aa6f58ead2f16a8f63db">qfile_mkdir</a> (const char *dirpath, mode_t mode, bool recursive)</td></tr>
<tr class="memdesc:ae623f84683c9aa6f58ead2f16a8f63db"><td class="mdescLeft">&#160;</td><td class="mdescRight">Attempts to create a directory recursively.  <br /></td></tr>
<tr class="separator:ae623f84683c9aa6f58ead2f16a8f63db"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af382e5541d166ecb6229dcac10a029ff"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#af382e5541d166ecb6229dcac10a029ff">qfile_check_path</a> (const char *path)</td></tr>
<tr class="memdesc:af382e5541d166ecb6229dcac10a029ff"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check path string contains invalid characters.  <br /></td></tr>
<tr class="separator:af382e5541d166ecb6229dcac10a029ff"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5386ae607fac65eb68fac034a8d4e612"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#a5386ae607fac65eb68fac034a8d4e612">qfile_get_name</a> (const char *filepath)</td></tr>
<tr class="memdesc:a5386ae607fac65eb68fac034a8d4e612"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get filename from filepath.  <br /></td></tr>
<tr class="separator:a5386ae607fac65eb68fac034a8d4e612"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aeb6452731c1582ac80bf26f91ce494c4"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#aeb6452731c1582ac80bf26f91ce494c4">qfile_get_dir</a> (const char *filepath)</td></tr>
<tr class="memdesc:aeb6452731c1582ac80bf26f91ce494c4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get directory suffix from filepath.  <br /></td></tr>
<tr class="separator:aeb6452731c1582ac80bf26f91ce494c4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac4728af539fcbdc7cd00e88834cfce74"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#ac4728af539fcbdc7cd00e88834cfce74">qfile_get_ext</a> (const char *filepath)</td></tr>
<tr class="memdesc:ac4728af539fcbdc7cd00e88834cfce74"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get extension from filepath.  <br /></td></tr>
<tr class="separator:ac4728af539fcbdc7cd00e88834cfce74"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af4b95ff503ddf957bc1d0d1a139a4be2"><td class="memItemLeft" align="right" valign="top">off_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#af4b95ff503ddf957bc1d0d1a139a4be2">qfile_get_size</a> (const char *filepath)</td></tr>
<tr class="memdesc:af4b95ff503ddf957bc1d0d1a139a4be2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get file size.  <br /></td></tr>
<tr class="separator:af4b95ff503ddf957bc1d0d1a139a4be2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3adcdafab36f7466a54538a3ae30a728"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#a3adcdafab36f7466a54538a3ae30a728">qfile_correct_path</a> (char *path)</td></tr>
<tr class="memdesc:a3adcdafab36f7466a54538a3ae30a728"><td class="mdescLeft">&#160;</td><td class="mdescRight">Correct path string.  <br /></td></tr>
<tr class="separator:a3adcdafab36f7466a54538a3ae30a728"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9b19d1e8419deecd9519759a5e37805a"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qfile_8c.html#a9b19d1e8419deecd9519759a5e37805a">qfile_abspath</a> (char *buf, size_t bufsize, const char *path)</td></tr>
<tr class="memdesc:a9b19d1e8419deecd9519759a5e37805a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Make full absolute system path string.  <br /></td></tr>
<tr class="separator:a9b19d1e8419deecd9519759a5e37805a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>File handling APIs. </p>

<p class="definition">Definition in file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="aee13ab9a468771f9b4e60ae117d1f613" name="aee13ab9a468771f9b4e60ae117d1f613"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aee13ab9a468771f9b4e60ae117d1f613">&#9670;&#160;</a></span>qfile_lock()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qfile_lock </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>fd</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Lock file. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">fd</td><td>file descriptor</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false.</dd></dl>
<div class="fragment"><div class="line"><span class="comment">// for file descriptor</span></div>
<div class="line"><span class="keywordtype">int</span> fd = open(...);</div>
<div class="line"><span class="keywordflow">if</span>(<a class="code hl_function" href="qfile_8c.html#aee13ab9a468771f9b4e60ae117d1f613">qfile_lock</a>(fd) == <span class="keyword">true</span>) {</div>
<div class="line">  (...atomic file access...)</div>
<div class="line">  <a class="code hl_function" href="qfile_8c.html#a964a6571f9178ce478d61fe7c4f1021e">qfile_unlock</a>(fd);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">// for FILE stream object</span></div>
<div class="line">FILE *fp = fopen(...);</div>
<div class="line"><span class="keywordtype">int</span> fd = fileno(fp);</div>
<div class="line"><span class="keywordflow">if</span>(<a class="code hl_function" href="qfile_8c.html#aee13ab9a468771f9b4e60ae117d1f613">qfile_lock</a>(fd) == <span class="keyword">true</span>) {</div>
<div class="line">  (...atomic file access...)</div>
<div class="line">  <a class="code hl_function" href="qfile_8c.html#a964a6571f9178ce478d61fe7c4f1021e">qfile_unlock</a>(fd);</div>
<div class="line">}</div>
<div class="ttc" id="aqfile_8c_html_a964a6571f9178ce478d61fe7c4f1021e"><div class="ttname"><a href="qfile_8c.html#a964a6571f9178ce478d61fe7c4f1021e">qfile_unlock</a></div><div class="ttdeci">bool qfile_unlock(int fd)</div><div class="ttdoc">Unlock file which is locked by qfile_lock()</div><div class="ttdef"><b>Definition</b> <a href="qfile_8c_source.html#l00098">qfile.c:98</a></div></div>
<div class="ttc" id="aqfile_8c_html_aee13ab9a468771f9b4e60ae117d1f613"><div class="ttname"><a href="qfile_8c.html#aee13ab9a468771f9b4e60ae117d1f613">qfile_lock</a></div><div class="ttdeci">bool qfile_lock(int fd)</div><div class="ttdoc">Lock file.</div><div class="ttdef"><b>Definition</b> <a href="qfile_8c_source.html#l00074">qfile.c:74</a></div></div>
</div><!-- fragment --> 
<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00074">74</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="a964a6571f9178ce478d61fe7c4f1021e" name="a964a6571f9178ce478d61fe7c4f1021e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a964a6571f9178ce478d61fe7c4f1021e">&#9670;&#160;</a></span>qfile_unlock()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qfile_unlock </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>fd</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Unlock file which is locked by <a class="el" href="qfile_8c.html#aee13ab9a468771f9b4e60ae117d1f613" title="Lock file.">qfile_lock()</a> </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">fd</td><td>file descriptor</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00098">98</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="af22eeea721ad66346d7e19f82b28fdb0" name="af22eeea721ad66346d7e19f82b28fdb0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af22eeea721ad66346d7e19f82b28fdb0">&#9670;&#160;</a></span>qfile_exist()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qfile_exist </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepath</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Check file existence. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepath</td><td>file or directory path</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if exists, otherwise returns false. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00122">122</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="a2e381f2cbdcbeeaee40dc754414cbe01" name="a2e381f2cbdcbeeaee40dc754414cbe01"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2e381f2cbdcbeeaee40dc754414cbe01">&#9670;&#160;</a></span>qfile_load()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * qfile_load </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepath</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *&#160;</td>
          <td class="paramname"><em>nbytes</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Load file into memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepath</td><td>file path </td></tr>
    <tr><td class="paramname">nbytes</td><td>has two purpost, one is to set how many bytes are readed. the other is actual the number loaded bytes will be stored. nbytes must be point 0 or NULL to read entire file.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>allocated memory pointer if successful, otherwise returns NULL.</dd></dl>
<div class="fragment"><div class="line"><span class="comment">// loading text file</span></div>
<div class="line"><span class="keywordtype">char</span> *text = (<span class="keywordtype">char</span> *)<a class="code hl_function" href="qfile_8c.html#a2e381f2cbdcbeeaee40dc754414cbe01">qfile_load</a>(<span class="stringliteral">&quot;/tmp/text.txt&quot;</span>, NULL);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// loading binary file</span></div>
<div class="line"><span class="keywordtype">int</span> binlen = 0;</div>
<div class="line"><span class="keywordtype">char</span> *bin = (<span class="keywordtype">char</span> *)<a class="code hl_function" href="qfile_8c.html#a2e381f2cbdcbeeaee40dc754414cbe01">qfile_load</a>(<span class="stringliteral">&quot;/tmp/binary.bin&quot;</span>, &amp;binlen);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// loading partial</span></div>
<div class="line"><span class="keywordtype">int</span> binlen = 10;</div>
<div class="line"><span class="keywordtype">char</span> *bin = (<span class="keywordtype">char</span> *)<a class="code hl_function" href="qfile_8c.html#a2e381f2cbdcbeeaee40dc754414cbe01">qfile_load</a>(<span class="stringliteral">&quot;/tmp/binary.bin&quot;</span>, &amp;binlen);</div>
<div class="ttc" id="aqfile_8c_html_a2e381f2cbdcbeeaee40dc754414cbe01"><div class="ttname"><a href="qfile_8c.html#a2e381f2cbdcbeeaee40dc754414cbe01">qfile_load</a></div><div class="ttdeci">void * qfile_load(const char *filepath, size_t *nbytes)</div><div class="ttdoc">Load file into memory.</div><div class="ttdef"><b>Definition</b> <a href="qfile_8c_source.html#l00159">qfile.c:159</a></div></div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>This method actually allocates memory more than 1 bytes than filesize then append NULL character at the end. For example, when the file size is 10 bytes long, 10+1 bytes will allocated and the last byte is always NULL character. So you can load text file and use without appending NULL character. By the way, the actual file size 10 will be returned at nbytes variable. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00159">159</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="a9133efad385ea27ea68c6df8fb94f1c4" name="a9133efad385ea27ea68c6df8fb94f1c4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9133efad385ea27ea68c6df8fb94f1c4">&#9670;&#160;</a></span>qfile_read()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * qfile_read </td>
          <td>(</td>
          <td class="paramtype">FILE *&#160;</td>
          <td class="paramname"><em>fp</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *&#160;</td>
          <td class="paramname"><em>nbytes</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Read data from a file stream. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">fp</td><td>FILE pointer </td></tr>
    <tr><td class="paramname">nbytes</td><td>has two purpose, one is to set bytes to read. the other is to return actual number of bytes loaded. 0 or NULL can be set to read file until the end.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>allocated memory pointer if successful, otherwise returns NULL.</dd></dl>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> binlen = 0;</div>
<div class="line"><span class="keywordtype">char</span> *bin = (<span class="keywordtype">char</span> *)<a class="code hl_function" href="qfile_8c.html#a9133efad385ea27ea68c6df8fb94f1c4">qfile_read</a>(fp, &amp;binlen);</div>
<div class="ttc" id="aqfile_8c_html_a9133efad385ea27ea68c6df8fb94f1c4"><div class="ttname"><a href="qfile_8c.html#a9133efad385ea27ea68c6df8fb94f1c4">qfile_read</a></div><div class="ttdeci">void * qfile_read(FILE *fp, size_t *nbytes)</div><div class="ttdoc">Read data from a file stream.</div><div class="ttdef"><b>Definition</b> <a href="qfile_8c_source.html#l00214">qfile.c:214</a></div></div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>This method append NULL character at the end of stream. but nbytes only counts actual readed bytes. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00214">214</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="aaef22ff4a8a80e6356583335cc34db64" name="aaef22ff4a8a80e6356583335cc34db64"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aaef22ff4a8a80e6356583335cc34db64">&#9670;&#160;</a></span>qfile_save()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">ssize_t qfile_save </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepath</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>buf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>append</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Save data into file. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepath</td><td>file path </td></tr>
    <tr><td class="paramname">buf</td><td>data </td></tr>
    <tr><td class="paramname">size</td><td>the number of bytes to save </td></tr>
    <tr><td class="paramname">append</td><td>false for new(if exists truncate), true for appending</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the number of bytes written if successful, otherwise returns -1.</dd></dl>
<div class="fragment"><div class="line"><span class="comment">// save text</span></div>
<div class="line"><span class="keywordtype">char</span> *text = <span class="stringliteral">&quot;hello&quot;</span>;</div>
<div class="line"><a class="code hl_function" href="qfile_8c.html#aaef22ff4a8a80e6356583335cc34db64">qfile_save</a>(<span class="stringliteral">&quot;/tmp/text.txt&quot;</span>, (<span class="keywordtype">void</span>*)text, strlen(text), <span class="keyword">false</span>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// save binary</span></div>
<div class="line"><span class="keywordtype">int</span> integer1 = 75;</div>
<div class="line"><a class="code hl_function" href="qfile_8c.html#aaef22ff4a8a80e6356583335cc34db64">qfile_save</a>(<span class="stringliteral">&quot;/tmp/integer.bin, (void*)&amp;integer, sizeof(int));</span></div>
<div class="ttc" id="aqfile_8c_html_aaef22ff4a8a80e6356583335cc34db64"><div class="ttname"><a href="qfile_8c.html#aaef22ff4a8a80e6356583335cc34db64">qfile_save</a></div><div class="ttdeci">ssize_t qfile_save(const char *filepath, const void *buf, size_t size, bool append)</div><div class="ttdoc">Save data into file.</div><div class="ttdef"><b>Definition</b> <a href="qfile_8c_source.html#l00283">qfile.c:283</a></div></div>
</div><!-- fragment --> 
<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00283">283</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="ae623f84683c9aa6f58ead2f16a8f63db" name="ae623f84683c9aa6f58ead2f16a8f63db"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae623f84683c9aa6f58ead2f16a8f63db">&#9670;&#160;</a></span>qfile_mkdir()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qfile_mkdir </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>dirpath</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">mode_t&#160;</td>
          <td class="paramname"><em>mode</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>recursive</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Attempts to create a directory recursively. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">dirpath</td><td>directory path </td></tr>
    <tr><td class="paramname">mode</td><td>permissions to use </td></tr>
    <tr><td class="paramname">recursive</td><td>whether or not to create parent directories automatically</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00312">312</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="af382e5541d166ecb6229dcac10a029ff" name="af382e5541d166ecb6229dcac10a029ff"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af382e5541d166ecb6229dcac10a029ff">&#9670;&#160;</a></span>qfile_check_path()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qfile_check_path </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>path</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Check path string contains invalid characters. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">path</td><td>path string</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if ok, otherwise returns false. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00337">337</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="a5386ae607fac65eb68fac034a8d4e612" name="a5386ae607fac65eb68fac034a8d4e612"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5386ae607fac65eb68fac034a8d4e612">&#9670;&#160;</a></span>qfile_get_name()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">char * qfile_get_name </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepath</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get filename from filepath. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepath</td><td>file or directory path</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>malloced filename string </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00356">356</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="aeb6452731c1582ac80bf26f91ce494c4" name="aeb6452731c1582ac80bf26f91ce494c4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aeb6452731c1582ac80bf26f91ce494c4">&#9670;&#160;</a></span>qfile_get_dir()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">char * qfile_get_dir </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepath</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get directory suffix from filepath. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepath</td><td>file or directory path</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>malloced filepath string </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00371">371</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="ac4728af539fcbdc7cd00e88834cfce74" name="ac4728af539fcbdc7cd00e88834cfce74"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac4728af539fcbdc7cd00e88834cfce74">&#9670;&#160;</a></span>qfile_get_ext()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">char * qfile_get_ext </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepath</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get extension from filepath. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepath</td><td>file or directory path</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>malloced extension string which is converted to lower case. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00386">386</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="af4b95ff503ddf957bc1d0d1a139a4be2" name="af4b95ff503ddf957bc1d0d1a139a4be2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af4b95ff503ddf957bc1d0d1a139a4be2">&#9670;&#160;</a></span>qfile_get_size()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">off_t qfile_get_size </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>filepath</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get file size. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filepath</td><td>file or directory path</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the file size if exists, otherwise returns -1. </dd></dl>

<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00410">410</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="a3adcdafab36f7466a54538a3ae30a728" name="a3adcdafab36f7466a54538a3ae30a728"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3adcdafab36f7466a54538a3ae30a728">&#9670;&#160;</a></span>qfile_correct_path()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">char * qfile_correct_path </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>path</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Correct path string. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">path</td><td>path string</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>path string pointer</dd></dl>
<dl class="section note"><dt>Note</dt><dd>This modify path argument itself.</dd></dl>
<div class="fragment"><div class="line"><span class="stringliteral">&quot;/hello//my/../world&quot;</span> =&gt; <span class="stringliteral">&quot;/hello/world&quot;</span></div>
<div class="line"><span class="stringliteral">&quot;././././hello/./world&quot;</span> =&gt; <span class="stringliteral">&quot;./hello/world&quot;</span></div>
<div class="line"><span class="stringliteral">&quot;/../hello//world&quot;</span> =&gt; <span class="stringliteral">&quot;/hello/world&quot;</span></div>
<div class="line"><span class="stringliteral">&quot;/../hello//world/&quot;</span> =&gt; <span class="stringliteral">&quot;/hello/world&quot;</span></div>
</div><!-- fragment --> 
<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00434">434</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
<a id="a9b19d1e8419deecd9519759a5e37805a" name="a9b19d1e8419deecd9519759a5e37805a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9b19d1e8419deecd9519759a5e37805a">&#9670;&#160;</a></span>qfile_abspath()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">char * qfile_abspath </td>
          <td>(</td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>buf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>bufsize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>path</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Make full absolute system path string. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">buf</td><td>buffer string pointer </td></tr>
    <tr><td class="paramname">bufsize</td><td>buffer size </td></tr>
    <tr><td class="paramname">path</td><td>path string</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>buffer pointer if successful, otherwise returns NULL.</dd></dl>
<div class="fragment"><div class="line"><span class="keywordtype">char</span> buf[PATH_MAX];</div>
<div class="line">chdir(<span class="stringliteral">&quot;/usr/local&quot;</span>);</div>
<div class="line"><a class="code hl_function" href="qfile_8c.html#a9b19d1e8419deecd9519759a5e37805a">qfile_abspath</a>(buf, <span class="keyword">sizeof</span>(buf), <span class="stringliteral">&quot;.&quot;</span>);    <span class="comment">// returns &quot;/usr/local&quot;</span></div>
<div class="line"><a class="code hl_function" href="qfile_8c.html#a9b19d1e8419deecd9519759a5e37805a">qfile_abspath</a>(buf, <span class="keyword">sizeof</span>(buf), <span class="stringliteral">&quot;..&quot;</span>);   <span class="comment">// returns &quot;/usr&quot;</span></div>
<div class="line"><a class="code hl_function" href="qfile_8c.html#a9b19d1e8419deecd9519759a5e37805a">qfile_abspath</a>(buf, <span class="keyword">sizeof</span>(buf), <span class="stringliteral">&quot;etc&quot;</span>);  <span class="comment">// returns &quot;/usr/local/etc&quot;</span></div>
<div class="line"><a class="code hl_function" href="qfile_8c.html#a9b19d1e8419deecd9519759a5e37805a">qfile_abspath</a>(buf, <span class="keyword">sizeof</span>(buf), <span class="stringliteral">&quot;/etc&quot;</span>); <span class="comment">// returns &quot;/etc&quot;</span></div>
<div class="line"><a class="code hl_function" href="qfile_8c.html#a9b19d1e8419deecd9519759a5e37805a">qfile_abspath</a>(buf, <span class="keyword">sizeof</span>(buf), <span class="stringliteral">&quot;/etc/&quot;</span>); <span class="comment">// returns &quot;/etc/&quot;</span></div>
<div class="ttc" id="aqfile_8c_html_a9b19d1e8419deecd9519759a5e37805a"><div class="ttname"><a href="qfile_8c.html#a9b19d1e8419deecd9519759a5e37805a">qfile_abspath</a></div><div class="ttdeci">char * qfile_abspath(char *buf, size_t bufsize, const char *path)</div><div class="ttdoc">Make full absolute system path string.</div><div class="ttdef"><b>Definition</b> <a href="qfile_8c_source.html#l00530">qfile.c:530</a></div></div>
</div><!-- fragment --> 
<p class="definition">Definition at line <a class="el" href="qfile_8c_source.html#l00530">530</a> of file <a class="el" href="qfile_8c_source.html">qfile.c</a>.</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_7b5d38f1875f1b693f62ca6a108a1129.html">utilities</a></li><li class="navelem"><a class="el" href="qfile_8c.html">qfile.c</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.7 </li>
  </ul>
</div>
</body>
</html>
